$(function(){
    $('#ssss').hover(function(){
        $(this).children('.liss').stop().slideToggle(300);
    })
 $('.liss li').hover(function(){
        $(this).children('.zhong').stop().slideToggle(300);
    })
})
        $(".header").load("../html/pubilchead.html")
    $(".footer").load("../html/publicfoot.html")
    $(function(){
	var ione = $(".one"),
		ithe = $(".the"),
		itwo = $(".two img"),
		tthe = $(".the img");
	
	var arr = ["../img/images/big/1.jpg","../img/images/big/2.jpg","../img/images/big/3.jpg","../img/images/big/4.jpg"];
	var oarr = ["../img/images/big/111.jpg","../img/images/big/222.jpg","../img/images/big/333.jpg","../img/images/big/444.jpg"];
	itwo.each(function(i){
		$(this).click(function(){
			$(".one img").attr("src",arr[i])
			tthe.attr("src",oarr[i])
			itwo.removeClass("active")
			$(this).addClass("active")
		})
		
		ione.mousemove(function(a){
			var evt = a || window.event
			ithe.css('display','block')
			var ot = evt.clientY-($(".one").offset().top- $(document).scrollTop())-87;
			var ol = evt.clientX-($(".one").offset().left- $(document).scrollLeft())-87;
			if(ol<=0){
				ol = 0;
			}
			if(ot<=0){
				ot = 0;
			}
			if(ol>=175){
				ol=175
			}
			if(ot>=175){
				ot=175
			}
			$("span").css({'left':ol,'top':ot})
			var ott = ot/350*800
			var oll = ol/350*800
			tthe.css({'left':-oll,'top':-ott})
		})
		ione.mouseout(function(){
			ithe.css('display','none')
		})
		
	})
	
	
	
	
})
var mySwiper = new Swiper ('.swiper-container', {
    loop: true,
    slidesPerView: 5,
    paginationClickable: true,
    spaceBetween: 30,
    nextButton: '.swiper-button-next',
    prevButton: '.swiper-button-prev',
    
  })     
  class shop{
    constructor(){
        this.init()
    }
    init(){
        $(()=>{
            let cookie_str=$.cookie('cart_nt')?$.cookie('cart_nt'):'';
            let cookie_obj=this.convertStrToObj(cookie_str);
            let sum = 0;
            for(let key in cookie_obj){
                sum += cookie_obj[key].num;
            }
            console.log(sum);
            $('.num').text(sum)
        })
        let cart_num=$('.num').text();
        let up=$('.up')
        let down=$('.down')
        let olddata=Number($('.num').val());
        up.click(()=>{
            olddata++;
            $('.num').val(olddata)
        })
        down.click(()=>{
            olddata--;
            if(olddata<=0){
                olddata=0
            }
            $('.num').val(olddata);
        })
        $('.btn_cart').click((e)=>{
            let shop_id=$('.shop_name').attr('shop_id');
            let shop_name=$('.shop_name').text();
            let shop_price=$('.price').text();
            let buy_bum=Number($('.num').val());
            let cookie_str=$.cookie('cart_nt')?$.cookie('cart_nt'):'';
            let cookie_obj=this.convertStrToObj(cookie_str);
            console.log(buy_bum)
            if(shop_id in cookie_obj){
                cookie_obj[shop_id].num+=buy_bum;
            }else{
                cookie_obj[shop_id]={
                    shop_name,
                    shop_price,
                    shop_color,
                    shop_size,
                    num:1
                }
            }

    
            // 
            // 
            // 
            var offset = $(".cart").offset();
            var img = $('.gan9').attr('src');
            var flyer = $('<img class="u-flyer" src="'+img+'">');
            $(flyer).css({width : 80,height:80})
            //飞
            flyer.fly({
                //起点
                start: {
                    left: $(".gan9").offset().left+$(".gan9").outerWidth()/2-40,
                    top: $(".gan9").offset().top-$(document).scrollTop()+$("..gan9").outerHeight()/2-40,
                },
                //终点
                end: {
                    left: offset.left,
                    top: offset.top-$(document).scrollTop(),
                    width: 0,
                    height: 0
                },
                //到达终点后调用的
                onEnd: function(){
                    cart_num=buy_bum+Number(cart_num);
                    console.log(cart_num)
                    $('.cart b').text(cart_num)
                    $.cookie(`cart_nt`,JSON.stringify(cookie_obj),{expires : 3,path : '/'})
                }
            });

        })
      
    }
    convertStrToObj(str){
        if(!str){
            return {};
        }
        return JSON.parse(str);
    }
}   
